import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_page/home_business/special_topic_detail/specail_topics_detail_controller.dart';
import 'package:xvideos/tools_base/loading/l_error_widget.dart';
import 'package:xvideos/tools_base/loading/loading_center_widget.dart';
import 'package:xvideos/tools_base/refresh/pull_refresh.dart';

import '../../../hj_model/home/module_detail_model.dart';
import '../home_cell_style/video_simple_cell_widget.dart';

class SpecailTopicsDetailPage extends StatelessWidget {
  final AllSection? originModel;

  const SpecailTopicsDetailPage(this.originModel, {super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SpecailTopicsController>(
      init: SpecailTopicsController(originModel),
      builder: (controller) => Scaffold(
        appBar: AppBar(
          title: Text(controller.title),
        ),
        body: Column(
          children: [
            Container(
              height: 32,
              margin: EdgeInsets.symmetric(horizontal: 32, vertical: 6),
              child: TabBar(
                tabAlignment: TabAlignment.fill,
                tabs: controller.sortTitles.map((e) {
                  return Container(
                    alignment: Alignment.center,
                    child: Text(e),
                  );
                }).toList(),
                labelStyle: TextStyle(fontSize: 14),
                labelColor: Color(0xE5FFFFFF),
                unselectedLabelStyle: TextStyle(fontSize: 14),
                unselectedLabelColor: Color(0x73FFFFFF),
                controller: controller.tabController,
                padding: EdgeInsets.zero,
                isScrollable: false,
                onTap: (index) {
                  controller.sort = index;
                  controller.fetchPageData(showLoading: true);
                },
                labelPadding: EdgeInsets.zero,
                indicator: BoxDecoration(),
                // indicator: ShapeDecoration(
                //   shape: StadiumBorder(),
                //   gradient: LinearGradient(
                //     begin: Alignment.centerLeft,
                //     end: Alignment.centerRight,
                //     colors: [Color(0xFF83A4F8), Color(0xFF2A5CDE)],
                //   ),
                // ),
              ),
            ),
            Expanded(
              child: pullYsRefresh(
                onInit: (ctr) => controller.refreshController = ctr,
                onRefresh: (_) => controller.fetchPageData(),
                onLoading: (_) => controller.fetchPageData(isRefresh: false),
                child: () {
                  if (controller.isLoading) return LoadingCenterWidget();
                  if (controller.dataSource.isEmpty) return CErrorWidget();
                  return GridView.builder(
                    padding: EdgeInsets.symmetric(horizontal: 10),
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                      crossAxisCount: 2,
                      crossAxisSpacing: 7,
                      mainAxisSpacing: 12,
                      childAspectRatio: 191 / 174,
                    ),
                    itemCount: controller.dataSource.length,
                    itemBuilder: (BuildContext context, int index) {
                      return SizedBox(
                        width: double.infinity,
                        height: double.infinity,
                        child: VideoSimpleCellWidget(
                          videoModel: controller.dataSource[index],
                        ),
                      );
                    },
                  );
                }(),
              ),
            )
          ],
        ),
      ),
    );
  }
}
